/**
 * Copyright 2019 [shujiang.yang], Inc. All rights reserved.
 * Email: 314938230@qq.com
**/
define("pages/jshjHjr/jshjHjr_jbxx_query", [
        "../../common/componts.js",
        "../../plugins/easyui/jquery-easyui-1.5.1/jquery.easyui.min",
        "../../plugins/easyui/jquery-easyui-1.5.1/easyloader",
        "../../plugins/artTemplate/artTemplate",
        "../../common/tools"
    ],
    function(require) {
        var componts = require("../../common/componts");
        var queryTableId="awdQueryTableId";
        var selectid;

        var getQueryDataGrid = function(){
            return $("#"+queryTableId);
        };

        var tableInit=function(){
            componts.initTable(queryTableId,{
                url:"/jshjHjr/list2jbxx",
                title:'',
                fit:true,
                // firstLoad:true,
                width:'100%',
                columns :  [
                    {
                        field: 'id',
                        title: '序号',
                        width:30,
                        formatter: function(value, rowData, rowIndex){
                            return '<input type="radio" name="ryRadio" id="ryRadio' + rowIndex + '" value="' + rowData.id + '" />';
                        }}
                    ,{field:'jsh',title:'拘室号',hidden:true,width:30,sortable:'false',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'xm',title:'姓名',hidden:true,width:50,sortable:'false',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'lxdh3',title:'联系电话3',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'zjlx3String',title:'证件类型',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'dw3',title:'单位3',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'gx3',title:'关系3',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'zz3',title:'住址3',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'jsbh',title:'监室编号',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'xm',title:'姓名',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'xb',title:'性别',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'zjlxString',title:'证件类型',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'lxdh',title:'联系电话',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'zjh',title:'证件号',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'dw',title:'单位',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'gx',title:'关系',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'zz',title:'住址',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'xm2',title:'姓名2',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'xb2',title:'性别2',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'zjlx2String',title:'证件类型',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'lxdh2',title:'联系电话2',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'zjh2',title:'证件号2',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'dw2',title:'单位2',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'gx2',title:'关系2',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'zz2',title:'住址2',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'xm3',title:'姓名3',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'xb3',title:'性别3',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'zjh3',title:'证件号3',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'operate',title:'详细信息',align:'center',width : 60,
                        formatter:function(value, row, index){
                            return '<a href="#" data-target="#ckPhoto" value="'+index+'" data-toggle="modal" class="easyui-linkbutton awd-query-view-detail"><img src="../../img/xq.png"></a>';
                        }}
                ] ,
                //基本信息双击事件
                onDblClickRow:function(rowIndex, rowData){
                    $("input[name='ryRadio']")[rowIndex].checked = true;
                    getQueryDataGrid().datagrid("selectRow", rowIndex);
                    selectid=rowData.id;
                },
                onLoadSuccess:function(data){
                    if(data.total>0){
                        getQueryDataGrid().datagrid("selectRow", 0);
                        $("input[name='ryRadio']")[0].checked = true;
                    }
                    //$("a[name='opera']").each(function(){
                    //    $(this).on('click',function () {
                    //        var index = $(this).attr('value');
                    //        var jbxx = data.rows[index];
                    //        kss.initJbxxxx(jbxx.gcbh,jbxx.rybh,jbxx.xm+"--详细信息");
                    //    });
                    //});
                },
                //单击行选中取消事件
                onClickRow:function(rowIndex, rowData){
                    if(selectid!=rowData.id){
                        $("input[name='ryRadio']")[rowIndex].checked = true;
                        selectid=rowData.id;
                    }else{
                        getQueryDataGrid().datagrid("unselectRow",rowIndex);
                        $("input[name='ryRadio']")[rowIndex].checked = false;
                        getQueryDataGrid().datagrid('clearSelections');
                        selectid="";
                    }
                }
                });
                //页面高度自适应
                getQueryDataGrid().datagrid('resize',{
                    height:($(window).height()-150)
                });
            };

        /**
         * 数据列表刷新加载
         */
        var loadDataGrid = function(){
            var formData = $(".awd-query-form").serializeObject();
            var queryParams = $.extend({},formData,{"state":"R8"});
            getQueryDataGrid().datagrid('clearSelections');
            getQueryDataGrid().datagrid('load',queryParams);
        };

        var bindAction=function(){
            //查询
            $(".query-btn").on("click",function(){
                loadDataGrid();
            });
            //打印
            $(".print-btn").on("click",function(){
                getQueryDataGrid().datagrid('print',{"title":"亲属会见_会见人"});
            });
            //导出Excel
            $(".export-btn").on("click",function(){
                getQueryDataGrid().datagrid('toExcel',{"filename":"亲属会见_会见人.xls"});
            });

           //单击行详情
           $(document).on('click','.awd-query-view-detail',function(){
                console.log('awd-query-view-detail',$(this).attr("value"));
            });

            /**
             * 绑定回车事件
             */
            $(window).keydown(function(event) {
                if (event.keyCode == 13) {
                    loadDataGrid();
                }
            });

        };

        //初始化
        (function(){
            componts.initSelectPage(undefined);
            componts.initSelect(undefined,undefined,undefined);
            tableInit();
            bindAction();
        })()
    });
